package com.heima.article.apis;

import com.heima.apis.ariticle.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.DelCommentDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.comment.dtos.CommentConfigDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class IArticleClientImpl implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;

    @Override
    @PostMapping("/api/article/api/save")
    public ResponseResult save(ArticleDto dto) {
        try {
            Long aLong = apArticleService.saveDto(dto);

            return ResponseResult.okResult(aLong);
        }catch (Exception e){

            return ResponseResult.errorResult(500,"发送没成功");
        }

    }

    @Override
    @PostMapping("/api/article/api/findById")
    public ResponseResult findById(@RequestParam("articleId") Long articleId) {
        ApArticle byId = apArticleService.getById(articleId);
        return ResponseResult.okResult(byId);
    }
    @Override
    @PostMapping("/api/article/api/findByPage")
    public PageResponseResult findByPage(@RequestBody ArticleCommentDto dto) {


        return apArticleService.findCommentByPage(dto);
    }


    @Override
    @DeleteMapping("/api/article/api/delComment")
    public ResponseResult delComment(@RequestBody DelCommentDto delCommentDto){
        return apArticleService.delComment(delCommentDto);
    }

    @Override
    @PutMapping("/api/article/api/changeArticle")
    public ResponseResult changeArticleStatus(@RequestBody CommentConfigDto dto) {
        return apArticleService.changeArticleStatus(dto);
    }

}
